//	ID : pallab81
// 	PROG : 531
// 	LANG : C++
// 	2011-07-27-17.09.57 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )


string tmp;
vector< string > s1,s2;
vector< vector<int> > cando;
string feed="";
inline bool read(){
    bool eof_=true;
    s1.clear();
    s2.clear();
    if( cin>>tmp ){
            eof_=false;
            s1.pb( tmp );
            while( cin>>tmp && tmp!="#"){
                s1.pb(tmp);
            }
            while( cin>>tmp && tmp!="#"){
                s2.pb(tmp);
            }

    }
return eof_;
}
inline void back_track(int _m, int _n){
    if( _m==0 || _n==0 ){
        return ;
    }
    if( s1[_m-1]==s2[_n-1] ){
        back_track(_m-1,_n-1);
        cout<<feed<<s1[_m-1];
        feed=" ";
    }
    else if( cando[_m-1][_n] > cando[_m][_n-1] ){
        back_track(_m-1,_n);
    }
    else{
        back_track(_m,_n-1);
    }
}
inline void proc(){
    int m = SZ(s1);
    int n = SZ(s2);
    cando.assign(m+10, vector<int>(n+10,0) );

    for(int i=1;i<=m;++i){
        for(int j=1;j<=n;++j){
            if(s1[i-1]==s2[j-1]){
                cando[i][j] = cando[i-1][j-1]+1;
            }
            else{
                cando[i][j] = max( cando[i-1][j], cando[i][j-1]);
            }
        }
    }

}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
    #endif
    while( read()==false ){
        feed="";
        proc();
        back_track(SZ(s1),SZ(s2));
        cout<<"\n";
    }

return 0;
}


